package com.wmm.servlet.classes;

import com.wmm.bean.Classes;
import com.wmm.bean.PageBean;
import com.wmm.service.ClassesService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet(name = "QueryClassServlet", urlPatterns = "/queryClass")
public class QueryClassServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        String className = request.getParameter("className");
        String classNo = request.getParameter("classNo");
        ClassesService classService = new ClassesService();
        if( "" == className ) {
            className = null;
        }
        if("" == classNo) {
            classNo = null;
        }

        //2. 调用service查询
        PageBean<Classes> queryList = classService.findQueryClassesByPage("1","5",classNo,className);
        //3. 将PageBean存入session
        HttpSession session = request.getSession();

        session.setAttribute("queryClassName",className);
        session.setAttribute("queryGrade",classNo);
        session.setAttribute("queryClassList",queryList);
        //4. 转发到show.jsp
        request.getRequestDispatcher("showClass.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
